package com.qst.itoffer.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@SuppressWarnings("ALL")
public class DBUtil {

    //    static String user = "ITTEST";
    static String user = "root";
    //    static String password = "123456";
    static String password = "q5588990";
    //    static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
    static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    //    static String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
    static String url = "jdbc:mysql://localhost:3306/TB_web"
            + "?serverTimezone=PRC&useUnicode=true"
            + "&characterEncoding=utf8&useSSL=false"
            + "&zeroDateTimeBehavior=convertToNull";

    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void closeJDBC(ResultSet rs, Statement stmt, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
